package com.youka.bussiness.common.base;

/*********************************
 * 文件名称: ChangeTypeEnum.java
 * 功能说明: 外部单据类型
 * 开发人员：liulw
 * 开发时间：8/3 0003 14:16
 *********************************/
public enum ChangeTypeEnum {

    //0 挂账 1支付宝 2 微信 3差价
    G1("G1", "挂账支付"),
    G2("G2", "支付挂账"),
    G113("S13", "支付失败退款");
    private String externalType;

    private String externalName;

    ChangeTypeEnum(String externalType, String externalName) {
        this.externalType = externalType;
        this.externalName = externalName;
    }

    /**
     * 根据传入的类型获取枚举或枚举值
     *
     * @param object
     * @return
     */
    public static Object getObject(Object object) {
        for (ChangeTypeEnum frs : ChangeTypeEnum.values()) {
            if (object instanceof String) {
                if (frs.getExternalType().equals(object)) {
                    return frs;
                }
            } else if (object instanceof Enum) {
                if (frs.equals(object)) {
                    return frs.getExternalType();
                }
            }
        }
        return null;
    }

    /**
     * 根据编码查找枚举
     *
     * @param code 编码
     * @return {@link } 实例
     **/
    public static ChangeTypeEnum find(String code) {
        for (ChangeTypeEnum frs : ChangeTypeEnum.values()) {
            if (frs.getExternalType().equals(code)) {
                return frs;
            }
        }
        return null;
        //throw new Exception("错误码", "根据code=" + code+ "获取渠道标示失败");
    }

    public String getExternalType() {
        return externalType;
    }

    public void setExternalType(String externalType) {
        this.externalType = externalType;
    }

    public String getExternalName() {
        return externalName;
    }

    public void setExternalName(String externalName) {
        this.externalName = externalName;
    }
}
